(function() {
	
	if (!window.CJ) {
		window.CJ = {};
	}

 /**
 * @class Vertical Class는 Key Event 를 처리한다.
 * @constructor Vertical
 * @description EventCtl Class 의 가상 메서드를  Overriding 하여 자식 객체만의 처리를 할 수 있다.
 */
	function Vertical () {}
	Vertical.prototype = new EventCtl();
	Vertical.prototype.left = function () {
		this.back();
	};
	Vertical.prototype.right = function (evt) {
		this.enter(evt);
	};
	Vertical.prototype.down = function() {
		if ($('li.focus', this.rootElem).length > 0) {
			this.moveV('next');
		}
	};
	Vertical.prototype.up = function(){
		if ($('li.focus', this.rootElem).length > 0) {
			this.moveV('prev');
		}
	};
	Vertical.prototype.moveV = function (downup) {
		var now = $("li.select", this.rootElem);
		var next = now[downup]();
		if (next.length>0) {
			$("li", this.rootElem).removeClass('select focus');
			next.addClass('select focus');
			this.rootElem.css({top : next.index() * this.moveDistance});
			
			//Extend는 마지막에
			this.extend();
		}
	};
	Vertical.prototype.pageUp = function() {
		var now = $("li.select", this.rootElem);
		var idx = now.index();
		idx = parseInt(idx - this.pageUnitCount) < 0 ?  0 : parseInt(idx-this.pageUnitCount);
		now.removeClass('select focus');
		$('li:nth-child('+parseInt(idx+1)+')', this.rootElem).addClass('select focus');
		this.rootElem.css('top', parseInt(idx*this.moveDistance)+'px');
		
		//Extend는 마지막에
		this.extend();
	};
	Vertical.prototype.pageDown = function(){
		var total = CJ.getStaticObject(this.name).totalCount;
		var now = $("li.select", this.rootElem);
		var idx = now.index();
		idx = parseInt(idx + this.pageUnitCount) > parseInt(total-1) ?  parseInt(total-1) : parseInt(idx + this.pageUnitCount);
		now.removeClass('select focus');
		$('li:nth-child('+parseInt(idx+1)+')', this.rootElem).addClass('select focus');
		this.rootElem.css('top', parseInt(idx*this.moveDistance)+'px');
		//Extend는 마지막에
		this.extend();
	};

	Vertical.prototype.bindEvent = function () {
		var self = this;
		this.rootElem
		.on("click", "li", function(evt) {
			// var obj = Scene.getDelegate();
			// if (self.name != obj.name) {
				// obj.back(evt);
			// }
			$(this).siblings().removeClass("select focus").end().addClass("select focus");

			$(this.parentElement).css({top : $(this).index() * self.moveDistance});

			self.enter(evt);
			//Extend는 마지막에
			if (evt.type == 'click') {
				self.extend();
			}
		});
	};
	CJ.Vertical = Vertical;


})();